import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

let toRemove = document.querySelector('.spinner-wrap');
if (toRemove.parentNode != null) {
    toRemove.parentNode.removeChild(toRemove);
}

export const defaultRouterMap = [
    { path: '/', name: 'root', redirect: '/homePage' },
    {
        path: '/homePage',
        name: 'homePage',
        component: () => import(/* webpackChunkName: "homePage" */ '@/views/home/homePage')
    },
    {
        path: '/redirect/:path*',
        name: 'redirect',
        component: () => import(/* webpackChunkName: "redirect" */ '@/views/redirect/index')
    }
];

const vueRouter = new Router({
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition;
        } else {
            if (from.meta.keepAlive) {
                from.meta.savedPosition = document.body.scrollTop;
            }
            return { x: 0, y: to.meta.savedPosition || 0 };
        }
    },
    routes: defaultRouterMap
});

export default vueRouter;
